const path = require("path");
const fs = require("fs");
const prompts = require("prompts");

async function selectProject() {
  const R = process.cwd();
  const projectsDir = path.join(R, 'src/projects');

  const projects = fs.readdirSync(projectsDir);

  const resp = await prompts([
    {
      type: 'select',
      name: 'project',
      message: '请选择项目',
      choices: projects.map(name => {
        return {
          title: name,
          value: name,
        }
      }),
    },
  ]);

  return resp.project;
}

exports.selectProject = selectProject;